package com.drojian.side;


import android.app.Service;
import android.content.Intent;
import android.media.MediaPlayer;
import android.os.IBinder;

import androidx.annotation.Nullable;

import com.drojian.demo.R;

public class BackgroundMusicService extends Service {

    @Nullable
    @Override
    public IBinder onBind(Intent intent) {
        return null;
    }


    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        String action = intent.getStringExtra("action");
        switch (action){
            case "root":
                root();
                break;
        }
        return super.onStartCommand(intent, flags, startId);
    }

    private MediaPlayer player;
    private void root() {
        if(player==null ){
            player = MediaPlayer.create(this,R.raw.music1);
            player.start();
        }else{
            if(player != null && player.isPlaying()){
                player.pause();
            }else {
                player.start();
            }
        }

    }

}
